import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:flutter_juwo/common/common_index.dart';

class LineChartSample4 extends StatelessWidget {
  var orderData;
  var peopleData;

  LineChartSample4(this.orderData, this.peopleData);

  @override
  Widget build(BuildContext context) {
    List<FlSpot> spotsOrder = [];
    List<FlSpot> spotsPeople = [];
    for (var item in orderData) {
      spotsOrder.add(FlSpot(item["x"].toDouble(), item["y"].toDouble()));
    }

    for (var item in peopleData) {
      spotsPeople.add(FlSpot(item["x"].toDouble(), item["y"].toDouble()));
    }
    return SizedBox(
      width: 300,
      height: 140,
      child: LineChart(
        LineChartData(
            //点击 活动时
            lineTouchData: LineTouchData(
              enabled: true,
              touchCallback: (lineTouchResponse) {
                // List<LineBarSpot> list = lineTouchResponse.props[0];
                // print("多少单");
                // print(list[0].bar.spots[list[0].spotIndex].y);
                // print("多少人");
                // print(list[1].bar.spots[list[0].spotIndex].y);
              },
              touchTooltipData: LineTouchTooltipData(
                  tooltipBgColor: Colours.cbg4,
                  getTooltipItems: (List<LineBarSpot> touchedSpots) {
                    List<LineTooltipItem> list = [];
                    LineTooltipItem item1 = LineTooltipItem(
                        "${touchedSpots[0].bar.spots[touchedSpots[0].spotIndex].y.toInt()}单",
                        TextStyles.custom(
                            30, Colours.cText7, Font.PingFangMedium));

                    LineTooltipItem item2 = LineTooltipItem(
                        "${touchedSpots[1].bar.spots[touchedSpots[0].spotIndex].y.toInt()}人",
                        TextStyles.custom(
                            30, Colours.cText8, Font.PingFangMedium));

                    list.add(item1);
                    list.add(item2);
                    return list;
                  }),
              getTouchedSpotIndicator:
                  (LineChartBarData barData, List<int> spotIndexes) {
                List<TouchedSpotIndicatorData> list = [];
                for (var item in spotIndexes) {
                  //每一个点都要添加 选中时的圆圈样式
                  TouchedSpotIndicatorData data = TouchedSpotIndicatorData(
                      FlLine(), FlDotData(getDotPainter: (FlSpot spot,
                          double xPercentage, LineChartBarData bar, int index,
                          {double size}) {
                    return FlDotCirclePainter(
                        radius: ScrUtil.w(6),
                        color: Color.fromARGB(255, 255, 255, 255),
                        strokeColor: barData.colors[0],
                        strokeWidth: ScrUtil.w(3));
                  }));
                  list.add(data);
                }
                return list;
              },
            ),
            //线 的数据
            lineBarsData: [
              LineChartBarData(
                //设置虚线
                //dashArray:[5,10],
                dotData: FlDotData(show: false),
                spots: spotsOrder,
                isCurved: true,
                barWidth: 2,
                colors: [Colours.cText7],
              ),
              LineChartBarData(
                dotData: FlDotData(show: false),
                spots: spotsPeople,
                isCurved: true,
                barWidth: 2,
                colors: [Colours.cText8],
              )
            ],
            minY: 0,
            gridData: FlGridData(getDrawingHorizontalLine: (value) {
              return FlLine(
                  color: Colours.cbg3, strokeWidth: 1, dashArray: [3, 3]);
            }),
            //不显示border
            borderData: FlBorderData(show: false),
            extraLinesData: ExtraLinesData(horizontalLines: []),
            //轴数据的样式
            titlesData: FlTitlesData(
                bottomTitles: SideTitles(
                    showTitles: true,
                    reservedSize: 14,
                    getTextStyles: (double value) {
                      return TextStyles.custom(
                          24, Colours.cText5, Font.PingFangRegular);
                    },
                    getTitles: (double value) {
                      return '${value.toInt()}';
                    }),
                leftTitles: SideTitles(
                  showTitles: true,
                  getTextStyles: (double value) {
                    return TextStyles.custom(
                        24, Colours.cText6, Font.PingFangRegular);
                  },
                  getTitles: (value) {
                    return '${value.toInt()}';
                  },
                ))),
      ),
    );
  }
}
